<?php
/** @var UserController $this */
/** @var User $model */

$this->pageTitle = '用户';
$this->breadcrumbs = array(
	'用户'
);
?>
<div class="page-header">
	<h1>用户 <?php echo CHtml::link('创建', array('create'), array('class' => 'btn btn-link')); ?></h1>
</div>

<?php
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
	'type' => 'horizontal',
));
$actions = array(
	'' => '批量操作',
	'active' => '激活验证选中用户',
	'notactive' => '不激活验证选中用户',
	'block' => '禁止选中用户',
	'unblock' => '解禁选中用户',
	//'delete' => '删除选中用户',
);

$allRoleList = Role::allList();
$addKey = '为选中的用户添加角色';
$removeKey = '为选中的用户删除角色';

foreach ($allRoleList as $name => $description) {
	$actions[$addKey]['add_role-' . $name] = $description;
	$actions[$removeKey]['remove_role-' . $name] = $description;
}

?>
<?php $this->widget('bootstrap.widgets.TbExtendedGridView', array(
	'id' => 'user-grid',
	'dataProvider' => $model->search(),
	'filter' => $model,
	'bulkActions' => array(
		'class' => 'YBulkActions',
		'align' => 'left',
		'actionButtons' => $actions,
	),
	'columns' => array(
		array(
			'name' => 'id',
			'class' => 'CCheckBoxColumn',
			'selectableRows' => 2,
			'checkBoxHtmlOptions' => array('name' => 'ids[]'),
		),
		array(
			'name' => 'id',
			'headerHtmlOptions' => array('class' => 'id-column'),
		),
		'username',
		'nickname',
		'email',
		array(
			'name' => 'roleNames',
			'value' => 'implode(", ", $data->roleList)',
			'filter' => $allRoleList,
		),
		array(
			'name' => 'status',
			'class' => 'YStatusColumn',
			'statusList' => $model->getStatusList(),
			'labelMap' => array(
				User::STATUS_NORMAL => YStatusColumn::LABEL_SUCCESS,
				User::STATUS_NOT_ACTIVE => YStatusColumn::LABEL_WARNING,
				User::STATUS_BLOCK => YStatusColumn::LABEL_IMPORTANT,
			),
			'filter' => $model->getStatusList(),
		),
		array(
			'name' => 'create_time',
			'class' => 'YDatetimeColumn',
			'type' => 'date',
			'filter' => YUtil::timeFilterList(),
		),
		array(
			'name' => 'login_time',
			'class' => 'YDatetimeColumn',
			'type' => 'date',
			'nullDisplay' => '从未登录',
			'filter' => array('0' => '从未登录') + YUtil::timeFilterList(),
		),
		array(
			'class' => 'bootstrap.widgets.TbButtonColumn',
			'template' => '{view} {update} {cancel}',
			'buttons' => array(
				'cancel' => array(
					'label' => '删除',
					'icon' => 'trash',
					'url' => 'Yii::app()->controller->createUrl("cancel", array("id"=>$data->id))',
					'visible' => '$data->id != Yii::app()->getUser()->getId() && $data->id != User::ROOT_ID',
				)
			)
		),
	),
)); ?>
<?php $this->endWidget(); ?>
